package com.zhugang.week13.recursion;

import java.util.HashMap;
import java.util.Map;

/**
 * @program algorithms
 * @description: numWays
 * @author: chanzhugang
 * @create: 2022/11/17 10:09
 */
public class NumWays {

    /**
     * 剑指offer 10-II 青蛙跳台阶问题
     * https://leetcode.cn/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/
     *
     * @param n
     * @return
     */
    Map<Integer, Integer> cache = new HashMap<>();
    int mod = 1000000007;

    public int numWays(int n) {
        /**
         * 递归，同斐波那契数列
         */
        if (n == 0 || n == 1) {
            return 1;
        }
        if (cache.containsKey(n)) {
            return cache.get(n);
        }
        int numWay = (numWays(n - 1) + numWays(n - 2)) % mod;
        cache.put(n, numWay);
        return numWay;
    }
}